
package pww.utils;
import a.annotation.Component;
import dbUtil.SQLExecteException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
@Component
public class ConnUtil {
    private static String driver = "com.mysql.cj.jdbc.Driver";
    private static String url = "jdbc:mysql://localhost:3306/project?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=true";
    private static String user = "root";
    private static String password = "123";

   static {
        try {
            Class.forName(driver);
        } catch (ClassNotFoundException e) {
            throw new SQLExecteException("Mysql driver class not found.", e);
        }
    }
    public static Connection getConnection() {
        try {
            return DriverManager.getConnection(url, user, password);
        } catch (SQLException e) {
            throw new SQLExecteException("Get connection fail.", e);
        }
    }

    public static void main(String[] args) {

        System.out.println(getConnection());
    }
}
